<template>
  <div class="leftCard">
    <ul>
      <li
        v-for="(item, index) in options"
        :key="index"
        :class="{ active: index === isActive }"
        @click="go(item, index)"
      >
        {{ item.label }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isActive: 0,
      options: [
        {
          value: -1,
          label: '全部方向'
        },
        ...this.$store.getters.getLeftSideCardItem
      ]
    }
  },
  created() {
    if (this.$route.query?.data) {
      this.isActive = JSON.parse(this.$route.query?.data)?.index
    } else {
      this.isActive = 0
    }
  },
  methods: {
    go(item, index) {
      const data = JSON.stringify({
        item,
        index
      })
      // console.log(this.$route.query?.data)
      if (this.$route.query?.data && this.$route.query?.data === data) {
        return
      }
      this.$router.replace({ query: { data } })
      this.isActive = index
      this.$emit('checkSideTab', this.options[this.isActive].value)
    }
  }
}
</script>

<style lang="scss" scoped>
.leftCard {
  width: 112px;
  background-color: #fff;
  margin: 6px 12px 6px 0px;
  padding: 20px 0 20px 0;
  ul > li {
    cursor: pointer;
    padding: 9px;
    text-align: center;
    transition: color 0.5s;
    border-right: 3px solid #fff;
    border-left: 3px solid #fff;
    color: rgb(102, 102, 102);
    font-weight: 500;
    font-size: 14px;
    &:hover {
      color: rgb(0, 170, 230);
    }
  }
  .active {
    border-left-color: rgb(0, 170, 230);
    color: rgb(0, 170, 230);
  }
}
</style>